﻿using Microsoft.AspNetCore.Mvc;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using WMS.PurchaseNoticeDetailTable;
using WMS.PurchaseNoticeDetailTable.DTO;

namespace WMS.Web.Controllers
{
    public class PurchaseNoticeDetailController : Controller
    {
        private readonly IPurchaseNoticeDetailAppService _purchaseNoticeDetailAppService;

        public PurchaseNoticeDetailController(IPurchaseNoticeDetailAppService purchaseNoticeDetailAppService)
        {
            _purchaseNoticeDetailAppService = purchaseNoticeDetailAppService;
        }

        /// <summary>
        /// 显示页面
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 进货通知明细显示
        /// </summary>
        /// <param name="customername">客户名称</param>
        /// <param name="prductname">商品名称</param>
        /// <param name="page">初始页</param>
        /// <param name="limit">每页几条数据</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetPurchaseNoticeDetailInfo(string? customername, string? prductname, int page, int limit)
        {
            var list = await _purchaseNoticeDetailAppService.GetPurchaseNoticeDetailInfo(customername, prductname, page, limit);
            return Json(new { data = list.Queryable, code = 0, count = list.RowCount });
        }
        /// <summary>
        /// 进货通知明细删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns
        [HttpGet]
        public async Task<JsonResult> DeletePurchaseNotice(int id)
        {
            var list = await _purchaseNoticeDetailAppService.DeletePurchaseNotice(id);
            return Json(new { code = list });
        }



        /// <summary>
        /// 添加页面
        /// </summary>
        /// <returns></returns>
        public IActionResult Create()
        {
            return View();
        }
        /// <summary>
        /// 进货通知明细添加
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<JsonResult> CreatePurchaseNotice(CreatePurchaseNoticeDTO dto)
        {
            var info= await _purchaseNoticeDetailAppService.CreatePurchaseNotice(dto);
            return Json(new { code = info });
        }


        /// <summary>
        /// 修改页面
        /// </summary>
        /// <returns></returns>
        public IActionResult Edit(int id)
        {
            ViewBag.id = id;
            return View();
        }
        /// <summary>
        /// 根据Id获取进货通知明细信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> FanTianPurchaseDetail(int id)
        {
            var list = await _purchaseNoticeDetailAppService.FanTianPurchaseDetail(id);
            return Json(new { data = list});
        }
        /// <summary>
        /// 进货通知明细修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<JsonResult> UpdatePurchaseNotice(UpdatePurchaseNoticeDTO dto)
        {
            var list= await _purchaseNoticeDetailAppService.UpdatePurchaseNotice(dto);
            return Json(new { code = list });
        }
    }
}
